home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / text / faqs / unix-faq.shell.zsh < prev    next >
Encoding:
Internet Message Format  |  1994-04-26  |  37.8 KB

  1. Subject: Z-shell Frequently-Asked Questions
  2. Newsgroups: comp.unix.shell,comp.answers,news.answers
  3. From: pws@s-a.amtp.liv.ac.uk (Peter Stephenson)
  4. Date: Mon, 25 Apr 1994 16:54:59 GMT
  5.  
  6. Archive-Name: unix-faq/shell/zsh
  7. Last-Modified: 1994/1/25
  8. Submitted-By: pws@s-a.amtp.liv.ac.uk (Peter Stephenson)
  9. Version: $Id: zsh.FAQ,v 1.24 1994/04/25 16:50:31 pws Exp pws $
  10. Frequency: Monthly
  11.  
  12. This document contains a list of frequently-asked (or otherwise
  13. significant) questions concerning the Z-shell, a command interpreter for
  14. many UNIX systems which is freely available to anyone with FTP access.
  15. Zsh is more powerful than every other common shell (sh, ksh, csh, tcsh
  16. and bash) put together.
  17.  
  18. Information on zsh is now available via the World Wide Web at
  19. http://crdmac11.colorado.edu:/zsh/zsh_home.html including this FAQ and
  20. much else (thanks to Mark Borges for this).
  21.  
  22. If you have never heard of `sh', `csh' or `ksh', then you are probably
  23. better off to start by reading a general introduction to UNIX rather
  24. than this document.
  25.  
  26. Another useful source of information is the collection of FAQ articles
  27. posted frequently to the Usenet news groups comp.unix.questions,
  28. comp.unix.shells and comp.answers with answers to general questions
  29. about UNIX.  The fifth of the seven articles deals with shells,
  30. including zsh, with a brief description of differences.  (This article
  31. also talks about shell startup files which would otherwise rate a
  32. mention here.)
  33.  
  34. If you just want to know how to get your hands on the latest version,
  35. skip to question 4); if you want to know what to do with insoluble
  36. problems, go to 22).
  37.  
  38. To encourage you to read on, if you don't know about zsh but are
  39. familiar with other UNIX shells, here are some things that zsh is
  40. particularly good at.  No claim of exclusivity is made, especially as
  41. shells copy one another, though in the areas of command line editing and
  42. globbing zsh is well ahead of the competition.  I am not aware of a
  43. major feature in any other freely-available shell which zsh does not
  44. also have.
  45.   Command line editing:
  46.     programmable completion: incorporates the ability to use
  47.       the full power of zsh globbing (compctl -g),
  48.     multi-line commands editable as a single buffer (even files!),
  49.     variable editing (vared),
  50.     command buffer stack,
  51.     print text straight into the buffer for immediate editing (print -z),
  52.     execution of unbound commands,
  53.     menu completion,
  54.     variable, editing function and option name completion,
  55.     inline expansion of variables, history commands.
  56.   Globbing --- extremely powerful, including:
  57.     recursive globbing (cf. find),
  58.     file attribute qualifiers (size, type, etc. also cf. find),
  59.     full alternation and negation of patterns.
  60.   Handling of multiple redirections (simpler than tee).
  61.   Large number of options for tailoring.
  62.   Path expansion (=foo -> /usr/bin/foo).
  63.   Adaptable messages for spelling, watch, time as well as prompt
  64.     (now including conditional expressions).
  65.   Named directories.
  66.   Comprehensive integer arithmetic.
  67.   Manipulation of arrays (including reverse subscripting).
  68.   Spelling correction.
  69.  
  70. Notation: Quotes `like this' are ordinary textual quotation
  71. marks.  Other uses of quotation marks are input to the shell.
  72.  
  73. If you are reading this file with GNU Emacs 19 and have my
  74. cross-referencing package xref.el (available from
  75. suna.amtp.liv.ac.uk:/pub/pws), I can supply a suitable set of
  76. cross-references to make reading the file easier.
  77.  
  78. Contents:
  79. 1) What is it?
  80. 2) On what machines will it run?
  81. 3) What's the latest version?
  82. 4) Where do I get it?
  83. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  84. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  85. 7) How do I turn off spelling correction for an individual command?
  86. 8) How do I get the meta key to work on my xterm?
  87. 9) Why does my terminal act funny in way x?
  88. 10) Why does `$var' where var="foo bar" not do what I expect?
  89. 11) My PATH, (MANPATH, ...) sometimes doesn't handle tildes.  What gives?
  90. 12) How does base arithmetic work?
  91. 13) How do I get a newline in my prompt?
  92. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  93. 15) How do I execute command `foo' within function `foo'?
  94. 16) Why can't I get zsh to work with SGI's `userenv'?
  95. 17) Why do history substitutions with single bangs do something funny?
  96. 18) Why does zsh kill off all my background jobs when I logout?
  97. 19) I don't have root access: how do I make zsh my login shell?
  98. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  99. 21) What bugs are currently known and unfixed?
  100. 22) Where do I report bugs, get more info / who's working on zsh?
  101. 23) What's on the wish-list?
  102. --- End of Contents ---
  103.  
  104.  
  105. 1) What is it?
  106.  
  107.   Zsh is a UNIX command interpreter (shell) which of the standard shells
  108.   most resembles the Korn shell (ksh), although it is not completely
  109.   compatible.  It includes enhancements of many types, notably in the
  110.   command-line editor, options for customising its behaviour, filename
  111.   globbing, features to make C-shell (csh) users feel more at home and
  112.   extra features drawn from tcsh (another `custom' shell).
  113.  
  114.   It was written by Paul Falstad <pf@z-code.com> when a student at
  115.   Princeton; however, Paul doesn't maintain it any more and enquiries
  116.   should be sent to the mailing list (see question 22).  It is freely
  117.   available to anyone under unrestrictive conditions.
  118.  
  119.   For more information, the files doc/intro.txt or doc/intro.troff
  120.   included with the source distribution are highly recommended.  A list
  121.   of features is given in FEATURES, also with the source.
  122.  
  123.  
  124. 2) On what machines will it run?
  125.  
  126.   Zsh was written for machines of the Berkeley UNIX family; most such
  127.   machines (and all the most popular) will run it without major surgery.
  128.   Modifications have been made so that it should work under SYSVR4-based
  129.   operating systems such as Solaris 2.x and OSF/1.  This best thing is
  130.   to suck it and see.  You may not have to change too much: if you do
  131.   change anything, arrange for the shell script `buildzsh' to set the
  132.   necessary #define's, etc., without human intervention.  Recent
  133.   additions include Convex, Unicos and Linux support; there is a project
  134.   to allow POSIX.1 compilation (but note that that zsh is not itself
  135.   particularly POSIX-compliant at the moment).  Success has been
  136.   obtained on older SYSVR3 systems, but you may need to modify the code.
  137.   
  138.   If you add support for a new machine, it would be appreciated if you
  139.   could alter buildzsh to configure zsh automatically and send the
  140.   required context diffs to the list (see question 22).
  141.  
  142.  
  143. 3) What's the latest version?
  144.   
  145.   The latest production version is 2.3.1; at this time zsh was not
  146.   ported to as many systems, so (for example) for Solaris 2 you are more
  147.   or less constrained to use the beta version.
  148.  
  149.   The current beta version is 2.4.  New patches occur frequently and are
  150.   added to the archive (next question).  At the time of writing the
  151.   latest patch level was 315.  Note that this `open' development system
  152.   does mean bugs are sometimes introduced into the most recent archived
  153.   version.  These are usually fixed quickly.  Note also that as the
  154.   shell changes, it may become incompatible with older versions; see the
  155.   end of question 21 for a partial list.
  156.  
  157.   The next production version will be 2.5 (2.4 will not be released, so
  158.   as to minimise confusion over version numbers).  It is expected that
  159.   no new features will be added before the release.
  160.  
  161.  
  162. 4) Where do I get it?
  163.  
  164.   Bas de Bakker (bas@phys.uva.nl) is in charge of the archive and the
  165.   latest version is available for users east of the Atlantic from:
  166.     carlo.phys.uva.nl(145.18.218.21):/pub/bas/zsh/zsh-2.4beta.tar.gz
  167.   The latest full release is in zsh-2.3.1.tar.gz in the same directory.
  168.   Note that this is in gzip format: you will need GNU gzip from your
  169.   nearest GNU archive to unpack it.  There is also a version under RCS
  170.   control which may be more suitable for source hackers.
  171.  
  172.   Rick Ohnemus has a reflector site in the USA:
  173.         ftp.sterling.com (192.124.9.1):/zsh
  174.  
  175.   The 2.3.1 distribution is also available from ftp.uu.net and mirrors
  176.   in the directory pub/shells/zsh.
  177.  
  178.  
  179. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  180.  
  181.   As has already been mentioned, zsh is most similar to ksh, while many
  182.   of the additions are to please csh users.
  183.  
  184.   i) ksh:
  185.  
  186.   Most features of ksh (and hence also of sh) are implemented in zsh;
  187.   problems can arise because the implementation is slightly different.
  188.   Note also that not all ksh's are the same either.  I have based this
  189.   on the 11/16/88f version of ksh.
  190.  
  191.   Various options can be turned on which will increase ksh
  192.   compatibility, though decrease zsh's abilities: see the manual entries
  193.   for IGNORE_BRACES (though brace expansion occurs in some versions of
  194.   ksh), KSH_OPTION_PRINT, NO_BANG_HIST, NO_EQUALS, NO_HUP, NO_RCS,
  195.   NO_SHORT_LOOPS, PROMPT_SUBST, RM_STAR_SILENT, SH_WORD_SPLIT (see
  196.   question 10) and SINGLE_LINE_ZLE.  Note that you can also disable any
  197.   built-in commands which get in your way.  If invoked as `ksh', the
  198.   shell will try and set suitable options.
  199.  
  200.   Here are some differences from ksh which might prove significant for
  201.   ksh programmers, some of which may be interpreted as bugs; there must
  202.   be more.  Note that this list is deliberately rather full and that
  203.   most of the items are fairly minor.  Those marked `*' perform in a
  204.   ksh-like manner if the shell is invoked with the name `ksh'.
  205.   
  206.   Syntax:
  207.   * Shell word splitting: see question 10).  (This is particularly
  208.       frequently asked about.)
  209.     Arrays are more csh-like than ksh-like:
  210.       subscripts start at 1, not 0; array[0] refers to array[1];
  211.       `$array' refers to the whole array, not $array[0];
  212.       braces are unnecessary: $a[1] == ${a[1]}, etc.
  213.     Coprocesses are established by `coproc'; `|&' behaves like csh.
  214.   Command line substitutions, globbing etc.:
  215.     The results of parameter substitutions are treated as plain text:
  216.       `foo="*"; print $foo' prints all files in ksh but * in zsh.
  217.     The $((...)) version of numeric evaluation is not implemented; use $[...].
  218.     Treatment of backslashes within backquotes is different.
  219.     $PSn do not do parameter substitution by default (use promptsubst option).
  220.     Globbing does not allow ksh-style `pattern-lists'.  Equivalents:
  221.       -------------------------------------------------------------------
  222.              ksh             zsh          Meaning
  223.             -----           -----        ---------
  224.            !(foo)            ^foo        Anything but foo.
  225.                       or   foo1~foo2     Anything matching foo1 but foo2.
  226.       @(foo1|foo2|...)  (foo1|foo2|...)  One of foo1 or foo2 or ...
  227.            ?(foo)           (foo|)       Zero or one occurrences of foo.
  228.            *(foo)           (foo)#       Zero or more occurrences of foo.
  229.            +(foo)         foo(foo)#      One or more occurrences of foo.
  230.       -------------------------------------------------------------------
  231.       The last two (with `#') require the EXTENDED_GLOB option.
  232.     Unquoted assignments do file expansion after ':'s (intended for PATHs).
  233.     `integer' does not allow -i; integers in bases other than 10 do not
  234.       have "base#" prefixed to them when printed.
  235.   Command execution:
  236.   * There is no ENV variable (use /etc/zshrc, ~/.zshrc; note also ZDOTDIR).
  237.     The PATH is not searched for commands specified at invocation without -c.
  238.   Aliases and functions:
  239.     The order in which aliases and functions are defined is significant
  240.       (function definitions with () expand aliases -- see question 6).
  241.     Aliases and functions cannot be exported.
  242.     There are no tracked aliases: command hashing replaces these.
  243.     The use of aliases for key bindings is replaced by `bindkey'.
  244.   Traps and signals:
  245.     By default, background jobs are killed when you log out:  see 18).
  246.     Traps and options are not local to functions; traps are not reset
  247.       automatically when called; traps are called as functions themselves
  248.       (this is a bug for the `trap "..." NAL' form of trap setting).
  249.     TRAPERR has become TRAPZERR (this was forced by UNICOS which has SIGERR).
  250.   Editing:
  251.     The options emacs, gmacs, trackall, viraw are not supported.
  252.       Use bindkey to change the editing behaviour: `set -o {emacs,vi}' 
  253.       become `bindkey -{e,v}'; for gmacs, go to emacs mode and use
  254.       `bindkey \^t gosmacs-transpose-characters'.  `Trackall' is replaced
  255.       by `hashcmds'.
  256.     The `keyword' option does not exist and -k is instead interactivecomments.
  257.       (`keyword' will not be in the next ksh release either.)
  258.     Management of histories in multiple shells is different:
  259.       the history list is not saved and restored after each command.
  260.     \ does not escape editing chars (use ^V).
  261.     Not all ksh bindings are set (e.g. `<ESC>#'; try <ESC>q).
  262.   * # in an interactive shell is not treated as a comment by default.
  263.   Built-in commands:
  264.     Some built-ins (r, autoload, history, integer ...) were aliases in ksh.
  265.     There is no built-in command newgrp: use a shell function, e.g.
  266.       newgrp () { ((SHLVL--)) ; exec command newgrp $* }
  267.       (in 2.4 you can get away with `alias newgrp="exec newgrp"'
  268.     `jobs' has no `-n' flag.
  269.     `read' has no `-s' flag.
  270.     In `let "i = foo"', foo is evaluated as a number, not an expression
  271.       (although in `let "i = $foo"' it is treated as an expression).
  272.   Other idiosyncrasies:
  273.     `select' always redisplays the list of selections on each loop.
  274.  
  275.   ii) csh:
  276.  
  277.   Although certain features aim to ease the withdrawal symptoms of csh
  278.   (ab)users, the syntax is in general rather different and you should
  279.   certainly not try to run scripts without modification.  The c2z script
  280.   is provided with the source (in scripts/c2z) to help convert .cshrc
  281.   and .login files; see also the next question concerning aliases,
  282.   particularly those with arguments.
  283.  
  284.   Csh-compatibility additions include:
  285.     Logout, rehash, source, (un)limit built-in commands.
  286.     *rc file for interactive shells.
  287.     Directory stacks.
  288.     Cshjunkie*, ignoreeof options.
  289.     The nonomatch option.
  290.     >&, |& etc. redirection.
  291.     foreach ... loops; alternative syntax for other loops.
  292.     Alternative syntax `if ( ... ) ...' (also `for', `which'; this now
  293.       requires the CSH_JUNKIE_PAREN option).
  294.     $PROMPT as well as $PS1, $status as well as $?, $#argv as well as $#, ....
  295.     Escape sequences via % for prompts.
  296.     Special array variables $PATH etc. are colon-separated, $path are arrays.
  297.     !-type history (which may be turned off via `setopt nobanghist').
  298.     Arrays have csh-like features (see i)).
  299.  
  300.   iii) tcsh:
  301.  
  302.   (The previous section applies too, of course.)  Certain features have
  303.   been borrowed from tcsh, including $watch, run-help, $savehist,
  304.   $histlit, periodic commands etc., extended prompts, sched and
  305.   which/where built-ins.  Programmable completion was inspired by, but
  306.   is entirely different to, tcsh's `complete'. (There is a perl script
  307.   called lete2ctl in the scripts directory of the source distribution to
  308.   convert `complete' to `compctl' statements.)  This list is not
  309.   definitive: some features have gone in the other direction.
  310.  
  311.   If you're missing the editor function run-fg-editor, try something
  312.   with bindkey -s (which binds a string to a keystroke), e.g.
  313.     bindkey -s '^z' '\eqfg %$EDITOR:t\n'
  314.   which pushes the current line onto the stack and tries to bring a job
  315.   with the basename of your editor into the foreground.  Bindkey -s
  316.   allows limitless possibilities along these lines.
  317.  
  318.   iv) bash:
  319.   
  320.   Zsh has almost all the features that bash has (and much more); in
  321.   addition it is about twice as fast, though this is less impressive
  322.   than it sounds.  With the new malloc by Sven Wischnowsky (only used if
  323.   you arranged for USE_ZSH_MALLOC to be defined in config.h when
  324.   compiling zsh), zsh uses about the same amount of heap memory as bash,
  325.   which was previously the biggest gripe.  The only feature I am aware
  326.   of that zsh doesn't have is setting a numerical value for ignoreeof
  327.   --- it's always 10 --- but of course I don't use bash :-).
  328.  
  329.   However, zsh has no claims towards Posix compliancy and will not use
  330.   GNU readline (zle is more powerful).  In fact, bash is intended more
  331.   as an enhanced sh than a ksh work-alike; it doesn't handle [[ ... ]],
  332.   for example.
  333.  
  334.  
  335. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  336.  
  337.   First of all, check you are using the syntax
  338.     alias newcmd='list of commands'
  339.   and not
  340.     alias newcmd 'list of commands'
  341.   which won't work. (It tells you if `newcmd' and `list of commands' are
  342.   already defined as aliases.)
  343.  
  344.   Otherwise, your aliases probably contain references to the command
  345.   line of the form `\!*', etc.  Zsh does not handle this behaviour as it
  346.   has shell functions which provide a way of solving this problem more
  347.   consistent with other forms of argument handling.  For example, the
  348.   csh alias
  349.     alias cd 'cd \!*; echo $cwd'
  350.   can be replaced by the zsh function,
  351.     cd() { builtin cd $*; echo $PWD; }
  352.   (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop)
  353.   or, perhaps better,
  354.     cd() { builtin cd $*; print -D $PWD; }
  355.   (which converts your home directory to a ~).  In fact, this problem is
  356.   better solved by defining the special function chpwd() (see the manual).
  357.   Note also that the `;' at the end of the function is optional in zsh,
  358.   but not in ksh or sh (for sh's where it exists).
  359.  
  360.   Here is Bart Schaefer's guide to converting csh aliases for zsh.
  361.  
  362.     1.  If the csh alias references "parameters" (\!:1 \!* etc.),
  363.         then in zsh you need a function (referencing $1 $* etc.).
  364.         Otherwise, you can use a zsh alias.
  365.  
  366.     2.  If you use a zsh function, you need to refer _at_least_ to
  367.         $* in the body (inside the { }).  Parameters don't magically
  368.         appear inside the { } the way they get appended to an alias.
  369.     
  370.     3.  If the csh alias references its own name (alias rm "rm -i"),
  371.         then in a zsh function you need the "command" keyword
  372.         (function rm() { command rm -i $* }), but in a zsh alias
  373.         you don't (alias rm="rm -i").
  374.  
  375.     4.  If you have aliases that refer to each other (alias ls "ls -C";
  376.         alias lf "ls -F" ==> lf == ls -C -F) then you must either:
  377.         a.  convert all of them to zsh functions; or
  378.         b.  after converting, be sure your .zshrc defines all of your
  379.             aliases before it defines any of your functions.
  380.  
  381.     Those first four are all you really need, but here are four more for
  382.     heavy csh alias junkies:
  383.  
  384.     5.  Mapping from csh alias "parameter referencing" into zsh function
  385.         (assuming shwordsplit is NOT set in zsh):
  386.              csh                   zsh
  387.             =====               ==========
  388.             \!*                 $*              (or $argv)
  389.             \!^                 $1              (or $argv[1])
  390.             \!:1                $1
  391.             \!:2                $2              (or $argv[2], etc.)
  392.             \!$                 $*[$#]          (or $argv[$#], or $*[-1])
  393.             \!:1-4              $*[1,4]
  394.             \!:1-               $*[1,$#-1]      (or $*[1,-2])
  395.             \!^-                $*[1,$#-1]
  396.             \!*:q               "$@"            ($*:q doesn't work (yet))
  397.             \!*:x               $=*             ($*:x doesn't work (yet))
  398.  
  399.     6.  Remember that it is NOT a syntax error in a zsh function to
  400.         refer to a position ($1, $2, etc.) greater than the number of
  401.         parameters. (E.g., in a csh alias, a reference to \!:5 will
  402.         cause an error if 4 or fewer arguments are given; in a zsh
  403.     function, $5 is the empty string if there are 4 or fewer
  404.     parameters.)
  405.  
  406.     7.  To begin a zsh alias with a - (dash, hyphen) character, use
  407.         "alias --":
  408.                  csh                            zsh
  409.             ===============             ==================
  410.             alias - "fg %-"             alias -- -="fg %-"
  411.  
  412.     8.  Stay away from "alias -g" in zsh until you REALLY know what
  413.         you're doing.
  414.  
  415.   There is one other serious problem with aliases: consider
  416.         alias l='/bin/ls -F'
  417.         l() { /bin/ls -la $* | more }
  418.   `l' in the function definition is in command position and is expanded
  419.   as an alias, defining `/bin/ls' and `-F' as functions which call
  420.   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  421.   `function' to define a function, which doesn't expand aliases.  It is
  422.   possible to argue for extra warnings somewhere in this mess.  Luckily,
  423.   it is not possible to define `function' as an alias.
  424.  
  425.  
  426. 7) How do I turn off spelling correction for an individual command?
  427.  
  428.   You presumably have `setopt correctall' in an initialisation file, so
  429.   that zsh checks the spelling of each word in the command line.  You
  430.   probably do not want this behaviour for commands which do not operate
  431.   on existing files.
  432.   
  433.   The answer is to alias the offending command to itself with
  434.   `nocorrect' stuck on the front, e.g.
  435.        alias mkdir='nocorrect mkdir'
  436.  
  437.  
  438. 8) How do I get the meta key to work on my xterm?
  439.  
  440.   As stated in the manual, zsh needs to be told about the meta key by
  441.   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the command
  442.   line.  You probably also need to tell the terminal driver to allow the
  443.   `meta' bit of the character through; `stty pass8' is the usual
  444.   incantation.  Sample .zshrc entry:
  445.     [[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
  446.   or, on SYSVR4-ish systems without pass8,
  447.     [[ $TERM = "xterm" ]] && stty -parenb -istrip cs8 && bindkey -me
  448.   (disable parity detection, don't strip high bit, use 8-bit characters).
  449.   Make sure this comes *before* any bindkey entries in your .zshrc which
  450.   redefine keys normally defined in the emacs/vi keymap.
  451.  
  452.  
  453. 9) Why does my terminal act funny in way x?
  454.  
  455.   If you are using an OpenWindows cmdtool as your terminal, any
  456.   escape sequences (such as those produced by cursor keys) will be
  457.   swallowed up and never reach zsh.  Either use shelltool or avoid
  458.   commands with escape sequences.  You can also disable scrolling from
  459.   the cmdtool pane menu (which effectively turns it into a shelltool).
  460.   If you still want scrolling, try using an xterm with the scrollbar
  461.   activated.
  462.  
  463.   If that's not the problem, and you are using stty to change some tty
  464.   settings, make sure you haven't asked zsh to freeze the tty settings:
  465.   type
  466.     ttyctl -u
  467.   before any stty commands you use.
  468.  
  469.   On the other hand, if you aren't using stty and have problems you may
  470.   need the opposite:  `ttyctl -f' freezes the terminal to protect it
  471.   from hiccups introduced by other programmes (kermit has been known to
  472.   do this).
  473.  
  474.   If _that's_ not the problem, and you are having difficulties with
  475.   external commands (not part of zsh), and you think some terminal
  476.   setting is wrong (e.g. ^V is getting interpreted as `literal next
  477.   character' when you don't want it to be), try
  478.     ttyctl -u
  479.     STTY='lnext "^-"' commandname
  480.   (in this example), or just export STTY for all commands to see.  Note
  481.   that zsh doesn't reset the terminal completely afterwards: just the
  482.   modes it uses itself and a number of special processing characters
  483.   (see the stty(1) manual page).
  484.  
  485.   After the release of version 2.5, there is likely to be an overhaul
  486.   which allows the terminal modes used by the shell to be modified
  487.   separately from those seen by external programmes.  This is partially
  488.   implemented already:  in 2.5, the shell will be less susceptible to
  489.   mode changes inherited from programmes.
  490.  
  491.  
  492. 10) Why does `$var' where var="foo bar" not do what I expect?
  493.  
  494.   In most Bourne-shell derivatives, multi-word variables such as
  495.     var="foo bar"
  496.   are split into words when passed to a command or used in a `for foo in
  497.   $var' loop.  By default, zsh does not have that behaviour: the
  498.   variable remains intact.  (This is not a bug!  See below.)  An option
  499.   (shwordsplit) exists to provide compatibility.
  500.   
  501.   For example, defining the function args to show the number of its
  502.   arguments:
  503.     args() { echo $#; }
  504.   and with our definition of vble,
  505.     args $vble
  506.   produces the output `1'.  After
  507.     setopt shwordsplit
  508.   the same function produces the output `2', as with sh and ksh.
  509.   
  510.   Unless you need strict sh/ksh compatibility, you should ask yourself
  511.   whether you really want this behaviour, as it can produce unexpected
  512.   effects for variables with entirely innocuous embedded spaces.  The
  513.   natural way to produce word-splitting behaviour in zsh is via arrays.
  514.   For example,
  515.     set -A array one two three twenty
  516.   (or
  517.         array=(one two three twenty)
  518.   if you prefer), followed by
  519.     args $array
  520.   produces the output `4', regardless of the setting of shwordsplit.
  521.   Arrays are also much more versatile than single strings.
  522.  
  523.   Note also the "$@" method of word splitting is always available in zsh
  524.   functions and scripts (though strictly this does array splitting, not
  525.   word splitting), also the substitution ${=foo} to toggle word
  526.   splitting on variable `foo'.
  527.  
  528.   Shwordsplit is set when zsh is invoked with the name `ksh'.
  529.  
  530.  
  531. 11) My PATH, (MANPATH, ...) sometimes doesn't handle tildes.  What gives?
  532.  
  533.   The code has recently been overhauled, so take a look at the latest
  534.   version of 2.4beta.  This guarantees that no ~user expansion (or
  535.   =command expansion, which takes place at the same time) will happen if
  536.   the tilde is quoted, and also rationalises PATH-type variables by
  537.   expanding all unquoted assignments as if they are colon-separated
  538.   lists (so you may need to add or subtract a few extra quotes, but the
  539.   results are more predictable).  In addition typeset, etc., now should
  540.   behave like ordinary assignments in this respect; previously tildes in
  541.   typeset assignments were unquotable.
  542.  
  543.  
  544. 12) How does base arithmetic work?
  545.  
  546.   The ksh syntax is now understood, i.e.
  547.         let 'foo = 16#ff'
  548.   or equivalently
  549.         (( foo = 16#ff ))
  550.   or even
  551.         foo=$[16#ff]
  552.   (note that `foo=$((16#ff))' is not yet supported).
  553.   The original syntax was
  554.     (( foo = [16]ff ))
  555.   --- this was based on a misunderstanding of the ksh manual page.  It
  556.   still works but its use is deprecated.
  557.   Then
  558.     echo $foo
  559.   gives the answer `255'.  It is possible to declare variables explicitly
  560.   to be integers, via
  561.     typeset -i foo
  562.   which has a different effect: namely the base used in the first
  563.   assignment (hexadecimal in the example) is subsequently used whenever
  564.   `foo' is displayed (although the internal representation is unchanged).
  565.   To ensure foo is always displayed in decimal, declare it as
  566.     typeset -i 10 foo
  567.   which requests base 10 for output.  You can change the output base of an
  568.   existing variable in this fashion.  Using the `$[ ... ]' method will
  569.   always display in decimal.
  570.  
  571.  
  572. 13) How do I get a newline in my prompt?
  573.  
  574.   You can place a literal newline in quotes, i.e.
  575.     PROMPT="Hi Joe,
  576.     what now?%# "
  577.   If you have the bad taste to set the option cshjunkiequotes, which
  578.   inhibits such behaviour, you will have to bracket this with 
  579.   `unsetopt cshjunkiequotes' and `setopt cshjunkiequotes', or put it in
  580.   your .zshrc before the option is set.
  581.   
  582.   Arguably the prompt code should handle `print'-like escapes.  Feel
  583.   free to write this :-).
  584.  
  585.  
  586. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  587.  
  588.   You probably have the extendedglob option set in which case ^ and #
  589.   are metacharacters.  ^a matches any file except one called a, so the
  590.   line is interpreted as bindkey followed by a list of files.  Quote the
  591.   ^ with a backslash or put quotation marks around ^a.
  592.  
  593.  
  594. 15) How do I execute command `foo' within function `foo'?
  595.  
  596.   The command `command foo' does just that.  You don't need this with
  597.   aliases, but you do with functions.  Note that error messages like
  598.         zsh: job table full or recursion limit exceeded
  599.   are a good sign that you tried calling `foo' in function `foo' without
  600.   using `command'.
  601.  
  602.  
  603. 16) Why can't I get zsh to work with SGI's `userenv'?
  604.  
  605.   It seems the Silicon Graphics `userenv' command interacts weirdly with
  606.   the line editor (zsh is not unique in this respect).  Add this line to
  607.   the top of your .zshenv file:
  608.         if [[ "${ENVONLY:-0}" -eq 1 ]]; then unsetopt zle; fi
  609.   --- which will turn the line editor off if it sees a `userenv' coming.
  610.   Don't turn zle back on with setopt until [[ $ENVONLY -ne 1 ]].
  611.  
  612.  
  613. 17) Why do history substitutions with single bangs do something funny?
  614.  
  615.   If you have a command like "echo !-2:$ !$", the first history
  616.   substitution then sets a default to which later history substitutions
  617.   with single unqualified bangs refer, so that !$ becomes equivalent to
  618.   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
  619.   to the last command.
  620.  
  621.  
  622. 18) Why does zsh kill off all my background jobs when I logout?
  623.  
  624.   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
  625.   you the option of having background jobs killed or not: the `nohup'
  626.   option exists if you don't want them killed.  Note that you can always
  627.   run programs with `nohup' in front of the pipeline whether or not the
  628.   option is set, which will prevent that job from being killed on
  629.   logout.  (Nohup is actually an external command.)
  630.  
  631.   The `disown' builtin is very useful in this respect: if zsh informs
  632.   you that you have background jobs when you try to logout, you can
  633.   `disown' all the ones you don't want killed when you exit.  This is
  634.   also a good way of making jobs you don't need the shell to know about
  635.   (such as commands which create new windows) invisible to the shell.
  636.  
  637.  
  638. 19) I don't have root access: how do I make zsh my login shell?
  639.  
  640.   Unfortunately, on many machines you can't use `chsh' to change your
  641.   shell unless the name of the shell is contained in /etc/shells, so if
  642.   you have your own copy of zsh you need some sleight-of-hand to use it
  643.   when you log on.  (Simply typing `zsh' is not really a solution since
  644.   you still have your original login shell waiting for when you exit.)
  645.   
  646.   The basic idea is to use `exec <zsh-path>' to replace the current
  647.   shell with zsh.  Often you can do this in a login file such as
  648.   .profile (if your shell is sh or ksh) or .login (if it's csh).  Make
  649.   sure you have some way of altering the file (e.g. via FTP) before you
  650.   try this as `exec' is often rather unforgiving.
  651.  
  652.   If you have zsh in a subdirectory `bin' of your home directory,
  653.   put this in .profile:
  654.     [ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
  655.   or if your login shell is csh or tcsh, put this in .login:
  656.     if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
  657.   (in each case the -l tells zsh it is a login shell).  
  658.  
  659.   It's not a good idea to put this (even without the -l) into .cshrc, at
  660.   least without some tests on what the csh is supposed to be doing, as
  661.   that will cause _every_ instance of csh to turn into a zsh and will
  662.   cause csh scripts (yes, unfortunately some people write these) which
  663.   do not call `csh -f' to fail.  If you want to tell xterm to run zsh,
  664.   change the SHELL environment variable to the full path of zsh at the
  665.   same time as you exec zsh.  If you have to exec zsh from your .cshrc,
  666.   a minimum safety check is `if ($?prompt) exec zsh'.
  667.  
  668.   If you like your login shell to appear in the process list as '-zsh',
  669.   you can link zsh to -zsh (e.g. by `ln -s ~/bin/zsh ~/bin/-zsh') and
  670.   change the exec to `exec -zsh'.  (Make sure -zsh is in your path.)
  671.   This has the same effect as the `-l' option.
  672.  
  673.   Footnote: if you DO have root access, make sure zsh goes in
  674.   /etc/shells on all appropriate machines, including NIS clients, or you
  675.   may have problems with FTP to that machine.
  676.  
  677.  
  678. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  679.  
  680.   People often ask why zsh has all these `unnecessary' csh-like features,
  681.   or alternatively why zsh doesn't understand more csh syntax.  This is
  682.   far from a definitive answer and the debate will no doubt continue.
  683.  
  684.   Paul's object in writing zsh was to produce a ksh-like shell which
  685.   would have features familiar to csh users.  For a long time, csh was
  686.   the preferred interactive shell and there is a strong resistance to
  687.   changing to something unfamiliar, hence the additional syntax and
  688.   CSH_JUNKIE options.  This argument still holds.  On the other hand,
  689.   the arguments for having what is close to a plug-in replacement for ksh
  690.   are, if anything, even more powerful:  the deficiencies of csh as a
  691.   programming language are well known (look in any Usenet FAQ archive, e.g.
  692.     rtfm.mit.edu:pub/usenet-by-group/news.answers/unix-faq/shell/csh-whynot
  693.   if you are in any doubt) and zsh is able to run many standard scripts
  694.   such as /etc/rc.
  695.   
  696.   Of course, this makes zsh rather large and quite messy so that it
  697.   seems to appeal mainly to hackers.  The only answer, perhaps not
  698.   entirely satisfactory, is that you have to ignore the bits you don't
  699.   want.
  700.  
  701.  
  702. 21) What bugs are currently known and unfixed?
  703.  
  704.   Here are some of the more well-known ones, very roughly in decreasing
  705.   order of significance.  Many of these can also be counted against
  706.   differences from ksh in question 5); note that this applies to the
  707.   latest beta version and that simple bugs are often fixed quite
  708.   quickly.  There is a file BUGS in the source distribution with more
  709.   detail.
  710.  
  711.   Pipelines ending in a while/until/for loop are uninterruptible.
  712.   Certain built-ins won't allow the `VAR=value command ...' assignment;
  713.     the ones that do don't unset VAR after use (may not really be a bug).
  714.     (N.B.: `exec foo=bar command' is a workaround for exec.)
  715.   The `histlit' option adds newlines to lines in the history
  716.     (and is broken in several other ways, e.g. !:x word selection;
  717.     it may be removed).
  718.   `time' is ignored with builtins and can't be used with {...} or (...);
  719.     in shells with no job control the command name is blank.
  720.   `set -x' (`setopt xtrace') doesn't show as much as it should.
  721.   The line number of errors inside control structures is always given
  722.     as the end of the structure (i.e. at `fi', `done', etc.).
  723.   $_ returns the last unexpanded word from the previous line (not command).
  724.   The :q modifier doesn't split words and -q and -x don't work for variables.
  725.   In vi mode, `u' can go past the original modification point.
  726.   Autocd won't use globbed filenames.
  727.   Linked directories can sometimes confuse zsh's idea of its cwd.
  728.   The singlelinezle option has problems with prompts containing escapes.
  729.   `wait' is not interruptible.
  730.   The =(..) substitution has a race condition which can hang the shell.
  731.   trap '' INT does not work with interactive commands.
  732.   read -q in a script assumes `n'.
  733.  
  734.   Note that a few recent changes introduce incompatibilities (these
  735.   are not bugs):
  736.   An option CSH_JUNKIE_PAREN has proved necessary for the syntax `if (
  737.     <condition> ) <code>' and for similar for and while (but not
  738.     foreach) commands.  This is because it is valid Bourne/Korn shell
  739.     syntax to have a subshell command immediately after if, and the
  740.     default syntax should be compliant with that.
  741.   Assignment of `...` and $(...) to variables in the form `foo=$(...)'
  742.     is now always scalar; previously the command output was split and
  743.     array assignment performed if more than one word resulted.  You
  744.     can still generate an array vie `foo=($(...))', which was always
  745.     the safe way of doing it.  Again, this is for Bourne/Korn compliance.
  746.   The -h option to compctl has been removed (use `-k hosts' for the
  747.     same effect); automatic handling of hosts after '@' has been removed
  748.     (use e.g. `compctl -u -x "n[-1,@]" -k hosts -- finger').
  749.   Handling of backslashes in `echo' and `print' has changed.
  750.   umask's behaviour with respect to symbolic operators has reversed
  751.     (and is now ksh-compatible).
  752.  
  753.   There is at least one common bug which is not due to zsh.  If you have
  754.   abnormal behaviour with file descriptor 4, it's because your password
  755.   database is being read from the Network Information System and
  756.   getpwent() left this fd open.
  757.  
  758.  
  759. 22) Where do I report bugs, get more info / who's working on zsh?
  760.  
  761.   The shell is being maintained by various (entirely self-appointed)
  762.   subscribers to the mailing list,
  763.     zsh-list@sterling.com so any suggestions, complaints,
  764.   questions and matters for discussion should be sent there.  If you
  765.   want someone to mail you directly, say so.  Most patches to zsh appear
  766.   there first.
  767.   
  768.   A lower-volume list,
  769.     zsh-announce@sterling.com
  770.   exists for announcements of new features and proposed changes
  771.   requiring some decisions.
  772.  
  773.   Both lists are handled by an automated server.  The instructions for
  774.   zsh-announce are the same as for zsh-list: just change zsh-list to
  775.   zsh-announce everywhere in the following.
  776.  
  777.   To join zsh-list, send email to
  778.     Majordomo@sterling.com
  779.   containing
  780.     subscribe zsh-list <optional-address>
  781.   where <optional-address> can be blank if you want to subscribe from
  782.   your current email address.  Send the message `help' to the same
  783.   address for help on the list server; `unsubscribe zsh-list' also
  784.   works. (Don't send this to the list!) The list manager, Rick Ohnemus,
  785.   can be reached at
  786.     owner-zsh-list@sterling.com
  787.   (or `rick' at the same adress).
  788.  
  789.   The list (everything since May 1992) is archived in
  790.     ftp.sterling.com:zsh/zsh-list/YY-MM
  791.   where YY-MM are the year and month in digits.
  792.  
  793.   Of course, you can also post zsh queries to the Usenet group
  794.   comp.unix.shell; if all else fails, you could even e-mail me.
  795.  
  796.  
  797. 23) What's on the wish-list?
  798.  
  799.   (The following will not be done before the release of 2.5.)
  800.   Ksh/sh compatibility could be improved if required.  This would
  801.     be a useful long term goal.
  802.   Option for glob qualifiers to follow perl syntax.
  803.   Option to quote !-history lexically via '' but not "".
  804.   Binding of shell functions (or commands?) to key strokes --
  805.     requires some way of accessing the editing buffer from functions
  806.     and probably of executing zle functions as a command.
  807.   trap '...' FOO should be eval'd rather than called as a function.
  808.   `PATH=' should clear the PATH:  it inserts `.'; use `unset PATH' or
  809.     `path=()' for the time being.  This is not really a bug as the .
  810.     would be used internally in any case (cf. ksh).
  811.   Users should be able to create their own foopath/FOOPATH array/path
  812.     combinations.
  813.   The introduction to zsh (intro.*) could do with an update to reflect
  814.     extended completion (in particular) and other recent additions.
  815.  
  816.  
  817. Acknowledgments:
  818.  
  819. Thanks to zsh-list, in particular Bart Schaefer, for suggestions
  820. regarding this document; thanks to Jim Mattson and more recently Bas de
  821. Bakker for their hard work as archivists, and to Peter Gray for
  822. maintaining the mailing list, without which zsh might easily have died,
  823. and to the latest list maintainer, Rick Ohnemus.  The world is eternally
  824. in the debt of Paul Falstad for inventing zsh in the first place.
  825.  
  826.